<?php

namespace App\Modules\LuckDraw\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AwardPoolModel extends Model {
    //用户的游戏资产，比如锤子，能量啥的
    protected $table = "luck_draw_award_pool";

    public static function get(int $poolId){
        return self::query()
            ->where('id', $poolId)
            ->where('status', 1)
            ->where('deleted', 0)
            ->first();
    }


    public function addActivityPool($desc,$luckId){
        return DB::table($this->table)->insert(['desc'=>$desc,'luck_id'=>$luckId]);
    }

    public function delActivityPool($id){
        return DB::table($this->table)->where('id',$id)->update(['deleted'=>1,'updated_at'=>date('Y-m-d H:i:s')]);
    }

    public function setActivityPool($id,$pool){
        return DB::table($this->table)->where('id',$id)->update(['pool'=>$pool]);
    }

    //更新奖池配置
    public function upActivityPool($id, $desc, $luckId, $is_open=0){
        return DB::table($this->table)->where('id',$id)->update(['desc'=>$desc,'updated_at'=>date('Y-m-d H:i:s'),'luck_id'=>$luckId, 'status'=>$is_open]);
    }

}
